package com.example.mymatch.controller;


import com.example.mymatch.model.Backwork;
import com.example.mymatch.service.IBackworkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * BackworkController层
 * 编写者：杨滢
 */

@Api(tags = "销假")
@RestController
public class BackworkController {
    @Autowired
    private IBackworkService backworkService;//对某个业务服务的内容进行定义规范  编写者：杨滢

    @ApiOperation(value = "查询所有销假信息",notes = "获取销假信息返回json字符串")
    @RequestMapping("/getStr14")
    public String getBackwork(){
        return "My backwork";
    }
    @CrossOrigin
    @ApiOperation(value = "对销假信息的添加方法")
    @GetMapping("/addBackwork")
    public int addBackwork(Backwork backwork){
        System.out.println("进入添加销假信息接口");
        return backworkService.insertBackwork(backwork);
    }

    @GetMapping("getAll14")
    @ApiOperation(value = "对销假信息的查询方法")
    public List<Backwork> getAllBackwork(Backwork backwork){
        System.out.println("进入查询方法");

        List<Backwork> listBackwork=backworkService.getAllBackwork(backwork);

        return listBackwork;
    }

    @PutMapping("/editBackwork")
    @ApiOperation(value = "对销假信息的修改方法")
    public int EditBackwork(@RequestBody Backwork backwork){
        System.out.println("进入销假修改方法");
        return backworkService.updateBackwork(backwork);
    }

    @GetMapping("/delBackwork")
    @ApiOperation(value = "对销假信息的删除方法")
    public int Delete(int id){
        System.out.println("进入销假删除方法");
        int returnValue=0;
        if (id!=0){
            Backwork backwork=new Backwork();
            backwork.setId(id);
            returnValue= backworkService.deleteBackwork(backwork);
        }
        return returnValue;
    }

    @GetMapping("/getOne14")
    @ApiOperation(value = "对单条销假信息的查询方法")
    public  Backwork getBackwork(int id){
        Backwork backwork=new Backwork();
        System.out.println("进入销假查询方法");
        if (id!=0){
            Backwork backwork1=new Backwork();
            backwork1.setId(id);
            backwork=backworkService.getBackwork(backwork1);
            System.out.println("返回的数据集合为："+backwork.getBackName());
        }
        return backwork;
    }
}
